<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="js/vue.js"></script>
    <script src="js/axios-0.18.0.js"></script>
</head>
<body>
<div id="app">
    username: <input type="text" v-model="user.username"> <br>
    password: <input type="password" v-model="user.password"> <br>

    <button @click="login">登录</button>
</div>
</body>

<script>
    new Vue({
        el:"#app",
        data:{
            user:{
                username:"",
                password:""
            }
        },
        methods:{
            login(){
                //发送异步请求，实现登录 post请求 + http://localhost:81/login, 要携带cookie
                axios.defaults.withCredentials = true;
                // axios.post("http://localhost:81/login","username="+this.user.username+"&password="+this.user.password).then();
                axios({
                    url:"http://localhost:81/login",
                    method:"post",
                    params:this.user  //发送的是键值对参数
                    // data:     发送的是json数据
                }).then(resp=>{
                    let result = resp.data;
                    //alert(result)
                    //保存登录成功后的jwt字符串
                    if (result.code == 1000){
                        localStorage.setItem("token",result.data);
                    }
                })
            }
        }
    });
</script>
</html>